//
//  WPTradeListViewController.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/5.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "WPTradeListViewController.h"
#import "WPRightTransModel.h"
#import "WPTradeListTableViewCell.h"
#import "WPTradeOrderViewController.h"
#import "WPTradeDetailViewController.h"
#import "WPTradeListViewModel.h"
#import "WPRightTransTicketDetailModel.h"


static NSString *const kUITableViewCellIdentifier = @"cellIdentifier";
static NSInteger sortBtnTag = 400;
@interface WPTradeListViewController ()<UITableViewDataSource, UITableViewDelegate, WPTradeListTableViewCellDelegate>
@property (nonatomic, strong) UIView * headView;/**< 头部视图 */
@property (nonatomic, strong) UIImageView * introImageView;/**< 海报 */
@property (nonatomic, strong) UIView * ticketView;/**< 票视图 */
@property (nonatomic, strong) UITextField * ticketCountTextField;/**< 成功交易张数 */
@property (nonatomic, strong) UILabel * allTicketCountLabel;/**< 总票数 */
@property (nonatomic, strong) UITextField * ticketIntroTextField;/**< 票数说明 */
@property (nonatomic, strong) UITextField * joinCountTextField;/**< 参与人数 */
@property (nonatomic, strong) UITextField * daysTextField;/**< 剩余天数 */
@property (nonatomic, strong) UITextField * joinIntroTextField;/**< 参与人数说明 */
@property (nonatomic, strong) UITextField * leftDaysTextField;/**< 剩余天数说明 */

@property (nonatomic, strong) UIView * progressTitle;/**< 进展图标题 */
@property (nonatomic, strong) UIView * priceTitle;/**< 价格走势标题 */
@property (nonatomic, strong) UIView * progressChart;/**< 进展图 */
@property (nonatomic, strong) UIView * trendChart;/**< 价格走势图 */
@property (nonatomic, strong) UIView * sortBtnView;/**< 排序按钮视图 */
@property (nonatomic, strong) UITableView * tradeTableView;/**< 交易期表格视图 */
@property (nonatomic, strong) NSMutableArray * tradeListArr;/**< 交易期数据源 */
@property (nonatomic, strong) UIImageView * seatImageView;/**< 座位示意图 */
@property (nonatomic , strong) UIView * mask;/**< 遮罩视图 */
@property (nonatomic, strong) WPRightTransTicketDetailModel * detailModel;/**< 演唱会详情 */
@property (nonatomic, assign) NSInteger currentPage;/**< 当前页码 */
@property (nonatomic, assign) NSInteger totalpages;/**< 总页码 */
@property (nonatomic, assign) NSInteger typeSort;/**< 类型排序 */
@property (nonatomic, strong) UILabel * noMoreLabel;/**< 没有说明 */

- (void)initializeDataSource; /**< 初始化数据源 */
- (void)initializeUserInterface; /**< 初始化用户界面 */
- (void)refreshData;/**< 刷新数据 */
@end

@implementation WPTradeListViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeDataSource];
    [self initializeUserInterface];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.typeSort = 0;
    [_tradeTableView.header beginRefreshing];
}
#pragma mark - init
- (void)initializeDataSource {
    self.tradeListArr = [NSMutableArray array];
    self.currentPage = 1;
    self.totalpages = 1;
    self.typeSort = 0;
}
- (void)initializeUserInterface {
    [self.view addSubview:self.tradeTableView];
}
#pragma mark - responds events
- (void)respondsToIntroImage {
    WPTradeDetailViewController * detailVC = [WPTradeDetailViewController new];
    detailVC.imageName = @"rain项目详情";
    [self pushToNextController:detailVC withVCTitle:@"项目详情"];
}
- (void)respondsToProgressSpreadBtn:(UIButton *)sender {
    sender.selected = !sender.selected;
}
- (void)respondsToPriceSpreadBtn:(UIButton *)sender {
    sender.selected = !sender.selected;
}
- (void)respondsToSortBtn:(UIButton *)sender {
    sender.selected = !sender.selected;
    switch (sender.tag - sortBtnTag) {
        case 0:
            [self getDataWithPageNumber:0 areaid:0 andTypeSort:-1 andDateSortAsc:-1 andPriceSortAsc:-1];
            break;
        case 1:
            if (sender.selected) {
                [self getDataWithPageNumber:0 areaid:-1 andTypeSort:-1 andDateSortAsc:1 andPriceSortAsc:-1];
            } else {
                [self getDataWithPageNumber:0 areaid:-1 andTypeSort:-1 andDateSortAsc:0 andPriceSortAsc:-1];

            }
            break;
        case 2: {
            _typeSort++;
            [self getDataWithPageNumber:0 areaid:-1 andTypeSort:_typeSort andDateSortAsc:-1 andPriceSortAsc:-1];
        }
            break;
        case 3:
            if (sender.selected) {
                [self getDataWithPageNumber:0 areaid:-1 andTypeSort:-1 andDateSortAsc:-1 andPriceSortAsc:1];
            } else {
                [self getDataWithPageNumber:0 areaid:-1 andTypeSort:-1 andDateSortAsc:0 andPriceSortAsc:0];
                
            }
            break;
        default:
            break;
    }
}
- (void)respondsToSeatImageView {
    if (self.seatImageView.superview) {
        [_seatImageView removeFromSuperview];
        [self.mask removeFromSuperview];
    }
}
#pragma mark - 刷新数据
- (void)refreshData {
    if (_currentPage > _totalpages) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [_tradeTableView.footer noticeNoMoreData];
        });
        return;
    }
    [self getDataWithPageNumber:_currentPage areaid:-1 andTypeSort:-1 andDateSortAsc:-1 andPriceSortAsc:-1];
}
- (void)getDataWithPageNumber:(NSInteger)pageNumber areaid:(NSInteger )areaid andTypeSort:(NSInteger)typeSort andDateSortAsc:(NSInteger)dateSort andPriceSortAsc:(NSInteger)priceSort {
    __weak typeof(self)weakself = self;
    [WPTradeListViewModel getTradeListWithPageNumber:pageNumber areaid:areaid typeid:typeSort dateSortAsc:dateSort priceSortAsc:priceSort andWithSuccessBlock:^(NSArray *resultList, WPRightTransTicketDetailModel *detailModel, NSInteger PageTotal) {
        if (_currentPage == 1 && _tradeListArr.count) {
            [_tradeListArr removeAllObjects];
        }
        for (WPRightTransModel * model in resultList) {
            [_tradeListArr addObject:model];
        }
        weakself.allTicketCountLabel.attributedText = [weakself configAllTicketCountAttributtedStringWithTicketCount:[NSString stringWithFormat:@"%@", detailModel.transactionNumber] andWithAllTicketCount:[NSString stringWithFormat:@"%@", detailModel.totalNumber]];
        weakself.joinCountTextField.text = [NSString stringWithFormat:@"%@", detailModel.involvementNumber];
        weakself.daysTextField.attributedText = [weakself configJoinPersonCountAttributtedStringWithString:[weakself transTimeWithTimeInterval:detailModel.endDate] andWithLastStr:@"天"];
        weakself.detailModel = detailModel;
        weakself.totalpages = PageTotal;
        if (_tradeListArr.count) {
            _tradeTableView.hidden = NO;
            if (weakself.noMoreLabel.superview) {
                [weakself.noMoreLabel removeFromSuperview];
            }
        } else {
            if (!weakself.noMoreLabel.superview) {
                [weakself.view addSubview:weakself.noMoreLabel];
            }
        }
        [_tradeTableView reloadData];
        [_tradeTableView.header endRefreshing];
        [_tradeTableView.footer endRefreshing];
    } andWithFailureBlock:^(NSString *fail) {
        if (_currentPage == 1 && [fail isEqualToString:@"无数据"]) {
            if (!weakself.noMoreLabel.superview) {
                [weakself.view addSubview:weakself.noMoreLabel];
            }
        }
        _tradeTableView.hidden = YES;
        [_tradeTableView.header endRefreshing];
        [_tradeTableView.footer endRefreshing];
    }];

}
#pragma mark - 协议UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _tradeListArr.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WPTradeListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kUITableViewCellIdentifier];
    if (!cell) {
        cell = [[WPTradeListTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kUITableViewCellIdentifier];
    }
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.delegate = self;
    [cell setModel:_tradeListArr[indexPath.section]];
    return cell;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.1;
}
//设置每一行高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 130*DHFlexibleHorizontalMutiplier();
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return section == 0 ? 295:5;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return self.headView;
    } else {
        return nil;
    }
}
#pragma mark - private protocol
- (void)respondsToPositionBtn {
    if (self.seatImageView.superview) {
        [_seatImageView removeFromSuperview];
    } else {
        [[UIApplication sharedApplication].keyWindow addSubview:_seatImageView];
        [[UIApplication sharedApplication].keyWindow addSubview:self.mask];
    }
}
- (void)respondsToBuyBtnWithRightTransModel:(WPRightTransModel *)model {
    WPTradeOrderViewController * vc = [WPTradeOrderViewController new];
    vc.model = model;
    vc.detailModel = _detailModel;
    [self pushToNextController:vc withVCTitle:@"订单详情"];
}
#pragma mark - private methods
#pragma mark - 配置文本
- (NSString *)transTimeWithTimeInterval:(NSNumber *)timeInterva {
    NSDate * currentDate = [NSDate date];
    NSDate * endDate = [NSDate dateWithTimeIntervalSince1970:[timeInterva doubleValue]/1000];
    NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"yyyyMMdd";
    NSString * currentDay = [formatter stringFromDate:currentDate];
    NSString * endDay = [formatter stringFromDate:endDate];
    NSDate * currentZero = [formatter dateFromString:currentDay];
    NSDate * endZero = [formatter dateFromString:endDay];
    NSTimeInterval currenTimeInterval = [endZero timeIntervalSinceDate:currentZero];
    NSString * subDay = [NSString stringWithFormat:@"%d",(int) currenTimeInterval/24/60/60];
    return subDay;
}
- (NSMutableAttributedString *)configAllTicketCountAttributtedStringWithTicketCount:(NSString *)tickCount andWithAllTicketCount:(NSString *)allCount {
    NSMutableAttributedString * attributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@张 / %@ 张", tickCount, allCount]];
    [attributedStr addAttribute:NSForegroundColorAttributeName value:COLOR_RGB(61, 61, 61, 1) range:NSMakeRange(0, attributedStr.length)];
    [attributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()] range:NSMakeRange(0, tickCount.length)];
    [attributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()] range:NSMakeRange(tickCount.length + 4, allCount.length)];
    [attributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()] range:NSMakeRange(tickCount.length , 1)];
    [attributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()] range:NSMakeRange(attributedStr.length -1 , 1)];

    return attributedStr;
}
- (NSMutableAttributedString *)configJoinPersonCountAttributtedStringWithString:(NSString *)str andWithLastStr:(NSString *)lastStr{
    NSMutableAttributedString * attributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@ %@", str, lastStr]];
    [attributedStr addAttribute:NSForegroundColorAttributeName value:COLOR_RGB(61, 61, 61, 1) range:NSMakeRange(0, attributedStr.length)];
    [attributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()] range:NSMakeRange(0, attributedStr.length - 1)];
    [attributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()] range:NSMakeRange(attributedStr.length -1, 1)];
    return attributedStr;
}
- (void)configSortBtn {
    NSArray * btnImages = @[@"A区.png", @"时间降序.png", @"类型.png", @"价格.png"];
    NSArray * btnSeletctImages = @[@"A区.png", @"时间升序.png", @"类型.png", @"价格升序.png"];
    for (int i = 0; i < btnImages.count; i++) {
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.bounds = CGRectMake(0, 0, 30*DHFlexibleHorizontalMutiplier(), 10*DHFlexibleHorizontalMutiplier());
        btn.center = CGPointMake((50+i%4*70)*DHFlexibleHorizontalMutiplier(), CGRectGetMidY(self.sortBtnView.bounds));
        [btn setImage:IMAGE_NAME(btnImages[i]) forState:UIControlStateNormal];
        [btn setImage:IMAGE_NAME(btnSeletctImages[i]) forState:UIControlStateSelected];
        btn.tag = sortBtnTag + i;
        [btn addTarget:self action:@selector(respondsToSortBtn:) forControlEvents:UIControlEventTouchUpInside];
        [_sortBtnView addSubview:btn];
    }
}
#pragma makr - getter
- (UIView *)headView {
    if (!_headView) {
        _headView = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_SIZE.width, 295*DHFlexibleHorizontalMutiplier())];
            [view addSubview:self.introImageView];
            [view addSubview:self.ticketView];
            UIView * sepa = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.ticketView.frame), SCREEN_SIZE.width, 3*DHFlexibleHorizontalMutiplier())];
            sepa.backgroundColor = COLOR_RGB(241, 241, 241, 1);
            [view addSubview:sepa];
            [view addSubview:self.progressTitle];
            [view addSubview:self.priceTitle];
            [view addSubview:self.sortBtnView];
            [self configSortBtn];
            view;
        });
    }
    return _headView;
}
- (UIImageView *)introImageView {
    if (!_introImageView) {
        _introImageView = ({
            UIImageView * view = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_SIZE.width, 144*DHFlexibleHorizontalMutiplier())];
            view.image = IMAGE_NAME(@"image3");
            view.userInteractionEnabled = YES;
            UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(respondsToIntroImage)];
            [view addGestureRecognizer:tap];
            view;
        });
    }
    return _introImageView;
}
- (UIView *)ticketView {
    if (!_ticketView) {
        _ticketView = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.introImageView.frame), SCREEN_SIZE.width, 44*DHFlexibleHorizontalMutiplier())];
//            [view addSubview:self.ticketCountTextField];
            [view addSubview:self.allTicketCountLabel];
            [view addSubview:self.ticketIntroTextField];
            
            [view addSubview:self.joinCountTextField];
            [view addSubview:self.joinIntroTextField];
            
            [view addSubview:self.daysTextField];
            [view addSubview:self.leftDaysTextField];
            UIView * line = [[UIView alloc]initWithFrame:CGRectMake(124*DHFlexibleHorizontalMutiplier(), 0, 1, CGRectGetHeight(view.frame))];
            line.backgroundColor = COLOR_RGB(241, 241, 241, 1);
            [view addSubview:line];
            UIView * lineRight = [[UIView alloc]initWithFrame:CGRectMake(221*DHFlexibleHorizontalMutiplier(), 0, 1, CGRectGetHeight(view.frame))];
            lineRight.backgroundColor = COLOR_RGB(241, 241, 241, 1);
            [view addSubview:lineRight];
            view;
        });
    }
    return _ticketView;
}
- (UITextField *)ticketCountTextField {
    if (!_ticketCountTextField) {
        _ticketCountTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 62*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            text.rightViewMode = UITextFieldViewModeAlways;
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 20*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            lab.text = @"张 / ";
            lab.textAlignment = NSTextAlignmentRight;
            lab.textColor = COLOR_RGB(61, 61, 61, 1);
            text.rightView = lab;
            text.textColor = COLOR_RGB(61, 61, 61, 1);
            text.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            text.text = _model.ticketCount;
            text.textAlignment = NSTextAlignmentRight;
            text.userInteractionEnabled = NO;
            text;
        });
    }
    return _ticketCountTextField;
}
- (UILabel *)allTicketCountLabel {
    if (!_allTicketCountLabel) {
        _allTicketCountLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 8*DHFlexibleHorizontalMutiplier(), 124*DHFlexibleHorizontalMutiplier(), 15*DHFlexibleHorizontalMutiplier())];
            
            lab.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            lab.userInteractionEnabled = NO;
            lab.textAlignment = NSTextAlignmentCenter;
            lab.attributedText = [self configAllTicketCountAttributtedStringWithTicketCount:_model.ticketCount andWithAllTicketCount:_model.allTicketCount];
            lab;
        });
    }
    return _allTicketCountLabel;
}
- (UITextField *)joinCountTextField {
    if (!_joinCountTextField) {
        _joinCountTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(124*DHFlexibleHorizontalMutiplier(), CGRectGetMinY(self.allTicketCountLabel.frame), 97*DHFlexibleHorizontalMutiplier(), 15*DHFlexibleHorizontalMutiplier())];
            text.rightViewMode = UITextFieldViewModeAlways;
            text.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(61, 61, 61, 1);
            text.textAlignment = NSTextAlignmentCenter;
            text.userInteractionEnabled = NO;
            text;
        });
    }
    return _joinCountTextField;
}
- (UITextField *)daysTextField {
    if (!_daysTextField) {
        _daysTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(221*DHFlexibleHorizontalMutiplier(), CGRectGetMinY(self.allTicketCountLabel.frame), 97*DHFlexibleHorizontalMutiplier(), 15*DHFlexibleHorizontalMutiplier())];
            text.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(61, 61, 61, 1);
            text.textAlignment = NSTextAlignmentCenter;
            text.userInteractionEnabled = NO;
            text;
        });
    }
    return _daysTextField;
}
- (UITextField *)ticketIntroTextField {
    if (!_ticketIntroTextField) {
        _ticketIntroTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.allTicketCountLabel.frame), 124*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            text.font = [UIFont systemFontOfSize:9*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(121, 121, 121, 1);
            text.textAlignment = NSTextAlignmentCenter;
            text.userInteractionEnabled = NO;
            text.text = @"成功交易   交易总数";
            text;
        });
    }
    return _ticketIntroTextField;
}
- (UITextField *)joinIntroTextField {
    if (!_joinIntroTextField) {
        _joinIntroTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.joinCountTextField.frame), CGRectGetMaxY(self.joinCountTextField.frame), 97*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            
            text.font = [UIFont systemFontOfSize:9*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(121, 121, 121, 1);
            text.userInteractionEnabled = NO;
            text.textAlignment = NSTextAlignmentCenter;
            text.text = @"参与人数";
            text;
        });
    }
    return _joinIntroTextField;
}
- (UITextField *)leftDaysTextField {
    if (!_leftDaysTextField) {
        _leftDaysTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(221*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.daysTextField.frame), 97*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            text.font = [UIFont systemFontOfSize:9*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(121, 121, 121, 1);
            text.textAlignment = NSTextAlignmentCenter;
            text.userInteractionEnabled = NO;
            text.text = @"剩余时间";
            text;
        });
    }
    return _leftDaysTextField;
}
- (UIView *)progressTitle {
    if (!_progressTitle) {
        _progressTitle = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.ticketView.frame)+5*DHFlexibleHorizontalMutiplier(), SCREEN_SIZE.width, 35*DHFlexibleHorizontalMutiplier())];
            view.backgroundColor = [UIColor whiteColor];
            UIView * line = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(view.bounds)-1, SCREEN_SIZE.width, 1)];
            line.backgroundColor = COLOR_RGB(241, 241, 241, 1);
            [view addSubview:line];
            UIImageView * image = [[UIImageView alloc]initWithFrame:CGRectMake(20*DHFlexibleHorizontalMutiplier(), 7*DHFlexibleHorizontalMutiplier(), 15*DHFlexibleHorizontalMutiplier(), 15*DHFlexibleHorizontalMutiplier())];
            image.image = IMAGE_NAME(@"jz");
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(40*DHFlexibleHorizontalMutiplier(), 0, 200, 30*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            lab.text = @"项目进展";
            UIButton * spreadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            spreadBtn.frame = CGRectMake(280*DHFlexibleHorizontalMutiplier(), 12*DHFlexibleHorizontalMutiplier(), 10*DHFlexibleHorizontalMutiplier(), 6*DHFlexibleHorizontalMutiplier());
            [spreadBtn setImage:IMAGE_NAME(@"xialajiantou") forState:UIControlStateNormal];
            [spreadBtn setImage:IMAGE_NAME(@"iconfont-shouqi") forState:UIControlStateSelected];
            [spreadBtn addTarget:self action:@selector(respondsToProgressSpreadBtn:) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:image];
            [view addSubview:lab];
            [view addSubview:spreadBtn];
            view;
        });
    }
    return _progressTitle;
}
- (UIView *)priceTitle {
    if (!_priceTitle) {
        _priceTitle = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.progressTitle.frame), SCREEN_SIZE.width, 35*DHFlexibleHorizontalMutiplier())];
            view.backgroundColor = [UIColor whiteColor];
            UIView * line = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(view.bounds)-1, SCREEN_SIZE.width, 1)];
            line.backgroundColor = COLOR_RGB(241, 241, 241, 1);
            [view addSubview:line];
            UIImageView * image = [[UIImageView alloc]initWithFrame:CGRectMake(20*DHFlexibleHorizontalMutiplier(), 7*DHFlexibleHorizontalMutiplier(), 15*DHFlexibleHorizontalMutiplier(), 15*DHFlexibleHorizontalMutiplier())];
            image.image = IMAGE_NAME(@"jgzs");
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(40*DHFlexibleHorizontalMutiplier(), 0, 200, 30*DHFlexibleHorizontalMutiplier())];
            lab.text = @"价格走势";
            lab.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            UIButton * spreadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            spreadBtn.frame = CGRectMake(280*DHFlexibleHorizontalMutiplier(), 12*DHFlexibleHorizontalMutiplier(), 10*DHFlexibleHorizontalMutiplier(), 6*DHFlexibleHorizontalMutiplier());
            [spreadBtn setImage:IMAGE_NAME(@"xialajiantou") forState:UIControlStateNormal];
            [spreadBtn setImage:IMAGE_NAME(@"iconfont-shouqi") forState:UIControlStateSelected];
            [spreadBtn addTarget:self action:@selector(respondsToProgressSpreadBtn:) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:image];
            [view addSubview:lab];
            [view addSubview:spreadBtn];
            view;
        });
    }
    return _priceTitle;
}
- (UIView *)sortBtnView {
    if (!_sortBtnView) {
        _sortBtnView = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.priceTitle.frame), SCREEN_SIZE.width, 35*DHFlexibleHorizontalMutiplier())];
            view.backgroundColor = COLOR_RGB(241, 241, 241, 1);
            view;
        });
    }
    return _sortBtnView;
}
- (UITableView *)tradeTableView {
    if (!_tradeTableView) {
        _tradeTableView = ({
            UITableView * tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, navBar_Fheight, SCREEN_SIZE.width, SCREEN_SIZE.height - navBar_Fheight) style:UITableViewStyleGrouped];
            tableview.dataSource = self;
            tableview.delegate = self;
            tableview.pagingEnabled = NO;
            tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
            tableview.backgroundColor = [UIColor whiteColor];
            __weak typeof(self)weakself = self;
            tableview.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
                _currentPage = 1;
                [weakself refreshData];
            }];
            tableview.footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
                _currentPage++;
                [weakself refreshData];
            }];
            tableview;
        });
    }
    return _tradeTableView;
}
- (UIImageView *)seatImageView {
    if (!_seatImageView) {
        _seatImageView = ({
            UIImageView * view = [[UIImageView alloc]initWithFrame:CGRectMake(18.5*DHFlexibleHorizontalMutiplier(), (SCREEN_SIZE.height - 400*DHFlexibleHorizontalMutiplier())/2, 283*DHFlexibleHorizontalMutiplier(), 400 *DHFlexibleHorizontalMutiplier())];
            view.image = IMAGE_NAME(@"detailSeat.jpg");
            view.userInteractionEnabled = YES;
            UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(respondsToSeatImageView)];
            [view addGestureRecognizer:tap];
            view;
        });
    }
    return _seatImageView;
}
- (UIView *)mask {
    if (!_mask) {
        _mask = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_SIZE.width, SCREEN_SIZE.height)];
            view.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.4];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(respondsToSeatImageView)];
            [view addGestureRecognizer:tap];
            view;
        });
    }
    return _mask;
}
- (UILabel *)noMoreLabel {
    if (!_noMoreLabel) {
        _noMoreLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREEN_SIZE.width, 30*DHFlexibleHorizontalMutiplier())];
            lab.center = self.view.center;
            lab.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            lab.textAlignment = NSTextAlignmentCenter;
            lab.text = @"暂无票务信息";
            lab;
        });
    }
    return _noMoreLabel;
}
@end
